<?php

define('DEDEINC', str_replace("\\", '/', __DIR__ ) );
define('DEDEROOT', str_replace("\\", '/', substr(DEDEINC,0,-11) ) );
define('DEDEDATA', DEDEROOT.'/data');
define('DEDETEMPLATE', DEDEROOT.'/templets');

require_once 'sqlin.php';
require_once 'config.php';
require_once DEDEINC.'/../class/mysql.class.php';
if(!$mydb) $mydb = new MYSQL($dbconf);

function getSystemSettings($expire=null){
	global $conf;

	if($expire===null) $expire= 7 * 60 * 60 * 60;
	$file = $_SERVER["DOCUMENT_ROOT"] . "/" . $conf['cache']['dir'] . '/systemSettings';
	if($expire && is_file($file) && filemtime($file) + $expire > $_SERVER["REQUEST_TIME"]){
		return $settings=unserialize(file_get_contents($file));
	}

	return array();
}

$_SETTINGS = getSystemSettings();

function ob_output_hander($html) {
	if (ord(substr($html, 0, 1)) === 239 && ord(substr($html, 1, 2)) === 187 && ord(substr($html, 2, 1)) === 191) $html = substr($html, 3);
	// gzip输出
	if(
		!headers_sent() && // 如果页面头部信息还没有输出
		extension_loaded("zlib") && // 而且zlib扩展已经加载到PHP中
		array_key_exists('HTTP_ACCEPT_ENCODING', $_SERVER) &&
		stripos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false // 而且浏览器说它可以接受GZIP的页面 
	) {
		$html = gzencode($html, 3);
		header('Content-Encoding: gzip'); 
		header('Vary: Accept-Encoding');
	}
	header('Content-Length: '.strlen($html));
	return $html;
}